/*
 * Package: org.grassfield.common.dao
 * FileName: UserDAO.java
 *  
 * Created by pandian on Jan 28, 2011
 */
package dao;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import bean.User;



/**
 * The Class UserDAO.
 */
public class UserDAO extends BaseDAO implements IUserDAO {

	@SuppressWarnings("unchecked")
	@Override
	public List<User> list() {
		return super.list("from User order by userName");
	}

	@Override
	public User getUser(String userName, String password) {
		List<Object> list = super.list("from User where userName=? and password=?", new Object[]{userName, password});
		if (list==null || list.size()==0)
			return null;
		return (User) list.get(0);
	}

	@Override
	@Transactional
	public User getUser(long id) {
		List<Object> list = super.list("from User where id=?", new Object[]{id});
		if (list==null || list.size()==0)
			return null;
		return (User) list.get(0);
	}

	@Override
	public User addUser(User user) {
		return (User) super.save(user);
	}
}
